layui.use(['element','form','table'],function(){
    var table = layui.table;
    var form = layui.form;
    var clientName = '';
    table.render({
        elem: '#demo'
        ,toolbar: '#toolbarDemo'
        ,url: '/copOrder' //数据接口
        ,page: true //开启分页
        ,where:{
            clientName
        }
        ,cols: [[ //表头
            {field: 'order_id',title: '订单编号', sort: true, width:120}
            // ,{field: 'clientName',title: '客户名', width:120}
            // ,{field: 'orderTotalPrice',title: '订单总价', width:120}
            // ,{field: 'orderStartTime', title: '订单创建时间'}
            // ,{field: 'orderUpdateTime', title: '订单更新时间'}
            // ,{field: 'orderStatusName', title: '订单状态'}
            // ,{field: 'userTrueName',title: '订单负责人'}
            // ,{field: 'orderUserId',title: '柜员编号'}
            ,{field: 'company_name',title: '公司名称'}
            ,{field: 'product_size',title: '数量'}
            ,{field: 'order_total_price',title: '订单总价格'}

            ,{field: 'order_remark',title: '订单备注'}
            ,{field: 'order_start_time',title: '订单起始时间'}
            ,{field: 'order_update_time',title: '订单更新时间'}
            ,{field: 'order_status',title: '订单状态'}
            ,{fixed: 'right',align:'center', toolbar: '#barDemo',title: '操作', width:120}
        ]]
        ,id:'orderList'
    });

    //工具栏监听事件--详情
    table.on('tool(test)', function(obj){
        var data = obj.data;
        var layEvent = obj.event;
        var id = obj.data.orderId;
        if(layEvent === 'detail'){
            window.location.href="OrderDetail.html?#"+id
        }
    });

    //头部工具栏监听事件--增加
    table.on('toolbar(test)', function(obj){
        var checkStatus = table.checkStatus(obj.config.id);
        switch(obj.event){
            case 'add':
                window.location.href="OrderAdd.html"
                break;
            case 'handOver':
                window.location.href="orderDelete.html"
                break;
        };
    });

    // //头部工具栏监听事件--交出
    // table.on('toolbar(test)', function(obj){
    //     var checkStatus = table.checkStatus(obj.config.id);
    //     switch(obj.event){
    //         case 'delete':
    //             window.location.href="OrderDelete.html"
    //             break;
    //     };
    // });

    var $ = layui.$, active = {
        reload: function(){
            var clientName = document.getElementById('orderCompanyName').value;

            var table = layui.table;
            table.reload('orderList', {
                where: {
                    clientName
                }
            });
        }
    };

    $('.searchTable .layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

});
